﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace VRacer.Packets
{
    public class PlayerCollisionPacket : PlayerPacket
    {
        private int _hitPlayerID;
        private int _collisionX;
        private int _collisionY;
        private int _lostMoves = 1;
        private int _hitPlayerLostMoves = 0;

        public PlayerCollisionPacket()
            : base(PacketType.PlayerCollision)
        {
            base.Length += 24;
        }

        public PlayerCollisionPacket(PlayerBase player, PlayerBase hitPlayer, Point collisonPoint)
            : this()
        {
            _id = player.ID;
            _hitPlayerID = hitPlayer.ID;
            CollisionPoint = collisonPoint;
        }

        public Point CollisionPoint
        {
            get { return new Point(_collisionX, _collisionY); }
            set
            {
                _collisionX = (int)value.X;
                _collisionY = (int)value.Y;
            }
        }

        public int HitPlayerID
        {
            get { return _hitPlayerID; }
            set { _hitPlayerID = value; }
        }

        public int HitPlayerLostMoves
        {
            get { return _hitPlayerLostMoves; }
            set { _hitPlayerLostMoves = value; }
        }

        public int LostMoves
        {
            get { return _lostMoves; }
            set { _lostMoves = value; }
        }

        public override void Read(System.IO.BinaryReader reader)
        {
            base.Read(reader);

            _id = reader.ReadInt32();
            _hitPlayerID = reader.ReadInt32();
            _collisionX = reader.ReadInt32();
            _collisionY = reader.ReadInt32();
            _lostMoves = reader.ReadInt32();
            _hitPlayerLostMoves = reader.ReadInt32();
        }

        public override void Write(System.IO.BinaryWriter writer)
        {
            base.Write(writer);

            writer.Write(_id);
            writer.Write(_hitPlayerID);
            writer.Write(_collisionX);
            writer.Write(_collisionY);
            writer.Write(_lostMoves);
            writer.Write(_hitPlayerLostMoves);
        }
    }
}
